package com.si.store.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.si.store.R;
import com.si.store.model.GamesAndApps;

public class AdapterApp extends ArrayAdapter<GamesAndApps>{
	Context context;
	int layoutId;
	List<GamesAndApps> lstData;
	ViewHolder viewHolder = null;
	LayoutInflater inflater;
	ViewHolder holder;
	class ViewHolder {
		private ImageView thumbItem;
		private TextView titleItem;
		
		public ViewHolder(View view) {
			thumbItem = (ImageView) view.findViewById(R.id.img_app);
			titleItem = (TextView) view.findViewById(R.id.txt_dowload_app);
		}
		
		public void setData(GamesAndApps app){
			thumbItem.setImageResource(app.getImg());
			titleItem.setText(app.getDowlaod());
		}
	}
	
	@SuppressWarnings("static-access")
	public AdapterApp(Context context, int textViewResourceId, List<GamesAndApps> lstData) {
		super(context, textViewResourceId, lstData);
		this.context = context;
		this.layoutId = textViewResourceId;
		this.lstData = lstData;
		inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); 
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(convertView == null){
			convertView = inflater.inflate(layoutId, parent, false);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else{
			holder = (ViewHolder) convertView.getTag();
		}
		holder.setData(lstData.get(position));
		return convertView;
	}
}
